﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using Microsoft.Xna.Framework;
using StreetlightGames.XnaEngine;

namespace StreetlightGames.SpaceShooter.Patterns
{
    [DataContract]
    public class MoveToTarget : Pattern
    {
        /// <summary>Gets or sets the Target value</summary>
        [DataMember]
        public Vector3 Target
        {
            get { return _target; }
            set { _target = value; }
        }
        private Vector3 _target;
        
        public MoveToTarget()
        {
        }

        public MoveToTarget(Vector3 target)
        {
            Target = target;
        }

        public override void Update(GameTime gameTime)
        {
            Vector3 delta = Target - Ship.Position;
            if (delta.Length() < 10)
            {
                MoveToNextPattern(gameTime);
            }
            else
            {
                delta.Normalize();
                Ship.Velocity = delta * Ship.Speed;
            }
        }

        public override string ToString()
        {
            return string.Format("Move To Target: Target:{0}", VectorHelper.ConvertVectorToString(Target));
        }
    }
}
